package com.bto.solar.work.controller;

import com.bto.solar.work.common.R;
import com.bto.solar.work.dto.order.QueryOrderReq;
import com.bto.solar.work.service.BtoBiService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author 王小波
 * @description:  统计分析
 * @date 2023/9/7 10:36
 */

@RestController
@RequestMapping("/bi")
public class BiController {
    @Autowired
    private BtoBiService btoBiService;


    @ApiModelProperty("签约量")
    @GetMapping("signed")
    public R<Integer> signed(@RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date startDate,
                             @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date endDate) {
        return R.ok(btoBiService.statisticsSinged(startDate , endDate , null));
    }

    @ApiModelProperty("组件扫码量")
    @GetMapping("zujian-scanned")
    public R<Integer> scanned(@RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date startDate,
                             @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date endDate) {
        return R.ok(btoBiService.statisticsZuJianScanned(startDate , endDate  , null));
    }


    @ApiModelProperty("项目建设中容量")
    @GetMapping("project-building")
    public R<Integer> projectBuilding(@RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date startDate,
                              @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date endDate) {
        return R.ok(btoBiService.statisticsBuilding(startDate , endDate , null));
    }

    @ApiModelProperty("项目待建设容量")
    @GetMapping("project-waiting-build")
    public R<Integer> projectWaitingBuild(@RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date startDate,
                                      @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date endDate) {
        return R.ok(btoBiService.statisticsWaitingBuild(startDate , endDate));
    }

    @ApiModelProperty("已并网容量")
    @GetMapping("grid-connection")
    public R<Integer> gridConnection(@RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date startDate,
                                      @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date endDate) {
        return R.ok(btoBiService.statisticsGridConnection(startDate , endDate , null));
    }


    @ApiModelProperty("公司容量排名")
    @GetMapping("company-capacity-statistics")
    public R companyCapacitySort(@RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date startDate,
                                     @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date endDate) {
        return R.ok(btoBiService.statisticsCompanyCapacity(startDate , endDate));
    }

    @ApiModelProperty("app订单页面-头部统计数据")
    @PostMapping("/app-order-page-head")
    public R appOrderPageHead(@RequestBody QueryOrderReq orderReq) {
        return R.ok(btoBiService.appOrderPageHead(orderReq));
    }

}
